package com.qingpeng.pay.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.qingpeng.pay.R;
import com.qingpeng.pay.api.Host;
import com.qingpeng.pay.api.RedBag;
import com.qingpeng.pay.base.BaseActivity;
import com.qingpeng.pay.beans.MoneyBean;
import com.qingpeng.pay.okhttp.RetrofitCreateHelper;
import com.qingpeng.pay.utils.ToastUtils;
import com.qingpeng.pay.views.TitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class UpQRCodeActivity extends BaseActivity {


    @BindView(R.id.title)
    TitleBar title;
    @BindView(R.id.number)
    TextView number;
    @BindView(R.id.number1)
    TextView number1;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_up_qrcode;
    }

    @Override
    protected int getRootViewId() {
        return 0;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected int getListViewId() {
        return 0;
    }


    @Override
    protected void onResume() {
        super.onResume();
        title.getLlLeft().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        title.getLlRight().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(UpQRCodeActivity.this,QRcodeActivity.class));
                finish();
            }
        });
        Call<MoneyBean> getaccount = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).getaccount();
        getaccount.enqueue(new Callback<MoneyBean>() {
            @Override
            public void onResponse(Call<MoneyBean> call, Response<MoneyBean> response) {
                MoneyBean body = response.body();
                if (body.getStatus()!=1){
                    ToastUtils.showToast(UpQRCodeActivity.this,body.getInfo());
                    return;
                }
                number.setText(body.getData().getWxQRnum()+"个");
                number1.setText(body.getData().getZfbQRnum()+"个");
            }

            @Override
            public void onFailure(Call<MoneyBean> call, Throwable t) {
                ToastUtils.showToast(UpQRCodeActivity.this, "网络请求错误,请稍后重试");
            }
        });
    }

    @OnClick({R.id.ll_weixin, R.id.ll_alipay})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_weixin:
                startActivity(new Intent(UpQRCodeActivity.this, QRcodeListActivity.class).putExtra("type","1"));
                break;
            case R.id.ll_alipay:
                startActivity(new Intent(UpQRCodeActivity.this, QRcodeListActivity.class).putExtra("type","2"));
                break;
        }
    }
}
